<?php
include ($cfgPaths['template'].'cms/app/blackboard/DataStore.o.inc.php');
$store = new DataStore();

if ($env->param('action'))
  $store->set('action',$env->param('action'));
else
  $store->set('action','showBids');

if (empty($params['instance']))
{
  print "<b>Error:</b> Keine Instanz angegeben!!";
}
elseif (empty($params['duration']))
{
  print "<b>Error:</b> Keine Dauer der Inserate angegeben!!";
}
elseif (empty($params['entriesPerPage']))
{
  print "<b>Error:</b> Keine Anzahl pro Seite angegeben!!";
}
else
{
  include ($cfgPaths['template'].'cms/app/blackboard/dbaBlackboard.o.inc.php');
  $dbab = new dbaBlackboard($udba);
  $store->set('script_name',$env->getServer('SCRIPT_NAME').'?doc_id='.$doc_id);
  $store->set('doc_id',$doc_id);
  switch ($store->get('action'))
  {
    case 'showNewBidForm':
      $store->set('newaction','addBid');
      include ($cfgPaths['template'].'cms/app/blackboard/form.inc.php');      	
      break;
    case 'showNewRequestForm':
      $store->set('newaction','addRequest');
      include ($cfgPaths['template'].'cms/app/blackboard/form.inc.php');      	
      break;
    case 'delBid':
      if (empty($is_live))
      {
      	$dbab->delEntry($env->param('id'));
      }
    case 'addBid':
      if ($store->get('action')!='delBid')
        $dbab->addEntry($params['instance'], 'BID', $env->param('name'),
           $env->param('email'), strip_tags($env->param('headline')), str_replace("\n",'<br/>',strip_tags($env->param('text'))));
    case 'showBids':
      $store->set('action','showBids');
      $entryarr = $dbab->getEntries($params['instance'],'BID',$params['duration'],(int)$env->param('currentPage'),$params['entriesPerPage']);
      if (is_array($entryarr[0]))
      {
      	$store->setRef('resultset',$entryarr[0]);
      	$store->set('num_pages',$entryarr[1]);
      	$store->set('currentPage',(int)$env->param('currentPage'));
        include ($cfgPaths['template'].'cms/app/blackboard/showData.inc.php');      	
      }
      else
      {
      	$store->set('errormsg','<b>Es ist ein Datenbankfehler aufgetreten.</b> Informieren Sie den Webmaster.');
      }
      break;
    case 'delRequest':
      if (empty($is_live))
      {
      	$dbab->delEntry($env->param('id'));
      }
    case 'addRequest':
      if ($store->get('action')!='delRequest')
        $dbab->addEntry($params['instance'], 'REQ', $env->param('name'),
          $env->param('email'), strip_tags($env->param('headline')), str_replace("\n",'<br/>',strip_tags($env->param('text'))));
    case 'showRequests':
      $store->set('action','showRequests');
      $entryarr = $dbab->getEntries($params['instance'],'REQ',$params['duration'],(int)$env->param('currentPage'),$params['entriesPerPage']);
      if (is_array($entryarr[0]))
      {
      	$store->setRef('resultset',$entryarr[0]);
      	$store->set('num_pages',$entryarr[1]);
      	$store->set('currentPage',(int)$env->param('currentPage'));
        include ($cfgPaths['template'].'cms/app/blackboard/showData.inc.php');      	
      }
      else
      {
      	$store->set('errormsg','<b>Es ist ein Datenbankfehler aufgetreten.</b> Informieren Sie den Webmaster.');
      }
      break;
  }
}
?>
